package com.JUtils.okhttp;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;
import java.util.concurrent.*;

public class HttpUtil {

    public static void main(String[] args) throws Exception {

        ExecutorService threadPool = new ThreadPoolExecutor(
                3,
                3,
                300,
                TimeUnit.MINUTES,
                new LinkedBlockingQueue<>(1),
                Executors.defaultThreadFactory()
        );

        threadPool.submit(() -> {
            try{
                process();
            }catch (Exception e){

            }
        });

        threadPool.submit(() -> {
            try{
                process();
            }catch (Exception e){

            }
        });
        threadPool.submit(() -> {
            try{
                process();
            }catch (Exception e){

            }
        });
        threadPool.submit(() -> {
            try{
                process();
            }catch (Exception e){

            }
        });

    }

    private static void process() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        for (int i = 0; i < 100000; i++) {
            Request request = new Request.Builder()
                    .get()
                    .url("http://94.191.85.29/user/test/gets")
                    .addHeader("X-Token", "808dc7bb967d7c543984262e7f078283")
                    .build();
            Response response = okHttpClient.newCall(request).execute();
          //  System.out.println(response.body().string());
        }
    }
}
